package checkers3d.logic;

import checkers3d.storage.DataManagerStats;
import java.awt.Point;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author racuna1
 */
public class GameMenuDrawLogin extends WindowLoginMP
{
    GameMenuDrawLogin(Point windowSize)
    {
        super(windowSize);

        setLoginObserver(new ObserverLogin());
    }

    /**
     * A observer for a button that creates and displays a new game object based
     * on the selected scenario.
     */
    private class ObserverLogin implements IInputObserverLogin
    {
        /**
         * The home player.
         */
        private Player home = null;

        /**
         * The visitor player.
         */
        private Player visitor = null;

        /**
         * Creates and displays a new game object based on the selected scenario.
         *
         * @param position Location of click within button.
         */
        public void onClick(Point position)
        {
            if(home != null && visitor != null)
            {
                try
                {
                    //update stats.
                    DataManagerStats.updateInidivualStatistic(home, false, false, true);
                    DataManagerStats.updateOponentStats(visitor, home, false, false, true);
                    DataManagerStats.updateInidivualStatistic(visitor, false, false, true);
                    DataManagerStats.updateOponentStats(home, visitor, false, false, true);
                    
                    //remove draw login window
                    GameMaster.getInstance().removeTopGUIContainer();
                    //remove game
                    GameMaster.getInstance().removeTopGUIContainer();
                }
                catch (IOException ex)
                {
                    Logger.getLogger(GameMenuDrawLogin.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        }

         /**
         * Key press observer that does nothing.
         *
         * @param key Key that was pressed.
         */
        public void onKeyPress(char key)
        {
            //do nothing.
        }

        /**
         * Sets the last validated home.
         *
         * @param player The home player.
         */
        public void setHome(Player player)
        {
            home = player;
        }

        /**
         * Sets the last validated visitor.
         *
         * @param player The visiting player.
         */
        public void setVisitor(Player player)
        {
            visitor = player;
        }
    }
}